﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: IRelationInfoCollection.cs
//
//  Description: Holds all relations of the persistent objects.
// 
//--------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Chili.Opf3.Relations;

namespace Chili.Opf3.Mapping
{
	/// <summary>
	/// Interface that represents a collection of <see cref="IRelationInfo">IRelationInfo</see> objects.
	/// </summary>
	/// <remarks>
	/// This interface represents a collection of <see cref="IRelationInfo">IRelationInfo</see> objects. An instance of this class
	/// is stored as list of all relations with an instance of the <see cref="TypeMapping">TypeMapping</see>.
	/// </remarks>
	public interface IRelationInfoCollection : IEnumerable<IRelationInfo>
	{
		/// <summary>
		/// Determines whether an element is in the collection.
		/// </summary>
		/// <param name="item">The object to locate in the collection.</param>
		/// <returns>True if item is found in the collection; otherwise, false.</returns>
		bool Contains(IRelationInfo item);

		/// <summary>
		/// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
		/// </summary>
		/// <param name="array">The one-dimensional System.Array that is the destination of the elements copied from collection. The System.Array must have zero-based indexing.</param>
		/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
		void CopyTo(IRelationInfo[] array, int arrayIndex);

		/// <summary>
		/// Gets the number of elements actually contained in the collection.
		/// </summary>
		int Count { get; }

		/// <summary>
		/// Returns the <see cref="ITypeRelationInfoCollection">ITypeRelationInfoCollection</see> object for the given type.
		/// </summary>
		/// <param name="type">Type of the related object.</param>
		ITypeRelationInfoCollection GetRelationMapping(Type type);

		/// <summary>
		/// Returns the <see cref="IRelationInfo">IRelationInfo</see> object associated with the 
		/// <see cref="RelationAttribute">RelationAttribute</see>'s name.
		/// </summary>
		/// <param name="name">The relation's name. The name is specified by setting 
		/// the <see cref="RelationAttribute">RelationAttribute</see>'s name property.</param>
		IRelationInfo GetRelationMapping(string name);

		/// <summary>
		/// Returns whether the collection is read-only.
		/// </summary>
		bool IsReadOnly { get; }

		/// <summary>
		/// Returns the item at the given index.
		/// </summary>
		/// <param name="index">The index of the item that is returned.</param>
		/// <returns>The item at the given index.</returns>
		IRelationInfo this[int index] { get; }

		/// <summary>
		/// Invalidates all relations in this collection.
		/// </summary>
		/// <param name="obj">The persistent object on which all relations are invalidated.</param>
		void InvalidateAll(object obj);
	}
}
